package com.shen.customer;


import javax.xml.crypto.dsig.keyinfo.KeyValue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author:shen
 * CreateDate:2020/5/6.
 * Function:
 */
public class CustomerServer {
    public  static Map<Integer,Customer> customerMap=new HashMap<>();

    public  static  int id=0;

    /**
     * 添加用户
     */
    public void addCustomer(String name){
        if(queryName(name)==null){
            Customer customer=new Customer(name);
            customerMap.put(id++,customer);
        }else{
            System.out.println("用户名不能重复");
        }

    }
    /**
     * 查找用户名
     */
    public Customer queryName(String name){
        Customer customer=null;
        for (Map.Entry<Integer,Customer> k:customerMap.entrySet()) {
            if(k.getValue().getName().equals(name)){
                customer=  k.getValue();
            }
        }
        return customer;
    }
    /**
     * 查找指定位置的用户
     */
    public Customer findIndexCus(int index){
        Customer customer = customerMap.get(index);
        return customer;
    }
    /**
     * 输出所有用户
     */
    public Map<Integer,Customer> queryAllCustomer(){
        return customerMap;
    }
}
